test_str='<div><div><div/></div><div></div></div>'
#<div><div></div></div><div></div><div><div></div><div></div></div>
def parse(txt,idx):
	obj={}
	temp_idx=0
	tag_start=txt.index('<',idx)
	tag_end=txt.index('>',idx)+1
	# print txt[tag_start:tag_end]
	tag_dict=parseTag(txt[tag_start:tag_end])
	tag=txt[tag_start:tag_end].split(' ')
	obj={tag:tag_dict}
	obj.setdefault('val',[])
	obj.setdefault('children',[])
	alone_flag=isAlone(txt[tag_start:tag_end])
	if alone_flag:
		return (obj,tag_end)
	has_children=txt.find('<',tag_end)
	if  has_children > 0:
		if has_children - tag_end > 0:		
			obj['val'].append(txt[tag_en:has_children-tag_end])
		sub_obj,sub_idx=parse(txt,has_children)
		idx=sub_idx-1
		obj['children'].append(sub_obj)
	edtag_start=txt.index('</',idx)
	edtag_end=txt.index('>',edtag_start)+1
	if txt[tag_end:edtag_start] != None:
		obj['val'].append(txt[tag_end:edtag_start])
	print txt[edtag_start:edtag_end]
	idx=edtag_end
	return (obj,idx)
def parseTag(tags):
	tag=tags.split(' ')
	print tag
	tag_dict={}
	for attrs in tag:
		if attrs != tag[0]:
			attr=attrs.split('=')
			tag_dict[attr[0]]=attr[1]
	return tag_dict

def isAlone(tag):
	# print tag
	if tag.find('/>') != -1:
		return True
	return False

if __name__ == '__main__':
	print parse(test_str,0)
	print len(test_str)
	# print 'dasdsd'.find('s',5)